# -*- coding: utf-8 -*-

import hashlib
from base import UserCase, Runner, TestSuite


class Case(UserCase):
    def test_login(self):
        pass

    def test_logout(self):
        res = self.c.open('/logout')
        self.assertEqual(res['code'], 0)

    def test_logout2(self):
        res = self.c.open('/logout', {'redirect': '/test'}, json=False)
        self.assertEqual(res, 'ok')

    def test_corp_login(self):
        p = {
            'name': self.randhan(8),
            'username': self.randchar(8),
            'password': hashlib.md5(self.randchar(8)).hexdigest(),
        }
        res = self.c.open('/api/corp/create', p)
        self.assertEqual(res['code'], 0)
        id = res['data']['id']

        pp = {
            'username': p['username'],
            'password': p['password'],
        }
        res = self.c.open('/login', pp)
        self.assertEqual(res['code'], 0)

        res = self.c.open('/api/session/read')
        self.assertEqual(res['data']['corp'], id)



test_list = [
    'test_login',
    'test_logout',
    'test_logout2',
    'test_corp_login',
]
Suite = TestSuite([Case(t) for t in test_list])


if __name__ == '__main__':
    Runner.run(Suite)


